<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Order extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table  =  $this->table('order',array('comment'=>'订单表'));
        $table->addColumn('user_id', 'integer',array('limit'  => 11,'default'=>0,'comment'=>'用户id',"null"=>true))
        ->addColumn('ware_id', 'integer',array('limit'  => 11,'default'=>0,'comment'=>'产品ID:一个产品ID对应多个产品计划ID',"null"=>true))
        ->addColumn('product_id', 'integer',array('limit'  => 11,'default'=>0,'comment'=>'产品计划ID:一个产品计划ID对应多个条款ID',"null"=>true))
        ->addColumn('clause_id', 'integer',array('limit'  => 11,'default'=>0,'comment'=>'条款ID:一个产品计划ID对应多个条款ID',"null"=>true))
        ->addColumn('ware_name', 'string',array('limit'  => 255,'default'=>'','comment'=>'产品名称',"null"=>true))
        ->addColumn('order_no', 'string',array('limit'  => 255,'default'=>'','comment'=>'订单号',"null"=>true))
        ->addColumn('policy_no', 'string',array('limit'  => 120,'default'=>'','comment'=>'保单号',"null"=>true))
        ->addColumn('policyNoList', 'text',array('comment'=>'保单号，可以为一个或多个保单号',"null"=>true))
        ->addColumn('commission_owner', 'string',array('limit'  => 120,'default'=>'','comment'=>'佣金归属人',"null"=>true))
        ->addColumn('seller', 'string',array('limit'  => 120,'default'=>'','comment'=>'出单人',"null"=>true))
        ->addColumn('product_name', 'string',array('limit'  => 255,'default'=>'','comment'=>'产品计划名称',"null"=>true))
        ->addColumn('clause_name', 'string',array('limit'  => 255,'default'=>'','comment'=>'条款名称',"null"=>true))
        ->addColumn('commission', 'float', array('limit' => "10,2",'default'=>0,"comment"=>"佣金，最多保留两位小数","null"=>true))
        ->addColumn('fundAccount_type', 'enum',array('values' => "0,1,2,3,4","comment"=>"资金账户类型:1=推广账户,2=保通账户","null"=>true))
        ->addColumn('commission_type', 'string',array('limit' => 50,"comment"=>"佣金类型:1-新单、3-撤单、4-退保、5-续保、6-附加险终止、7-减保、9-协议退保、10-一次性追加、13-生效前撤单、14-实收回退、15-犹豫期退保、16-活动佣金、17-冻结挂起、18-邀请佣金、19-附加险终止、-1-其他","null"=>true))
        ->addColumn('settle_status', 'string',array('limit' => 50,"comment"=>"推广账户:nm-暂无生效日,NY-待生效,NN-已生效待结算,C-结算中,Y-已结算 保通账户:N -待结算,Y -已结算,F -冻结","null"=>true))
        ->addColumn('remake', 'string',array('limit'  => 500,'default'=>'','comment'=>'备注',"null"=>true))
        ->addColumn('pay', 'string',array('limit' =>250,"comment"=>"交费期间","null"=>true))
        ->addColumn('expires', 'string',array('limit' =>250,"comment"=>"保障期间","null"=>true))
        ->addColumn('pay_freq', 'string',array('limit' =>250,"comment"=>"交费方式:枚举值:一次交清,年交,月交,季交,半年交","null"=>true))
        ->addColumn('insure_data', 'string',array('limit' =>50,"comment"=>"承保时间","null"=>true))
        ->addColumn('creat_date_end', 'string',array('limit' =>50,"comment"=>"佣金生成时间（佣金生成时间一般为承保后立即生成）","null"=>true))
        ->addColumn('effective_date', 'string',array('limit' =>50,"comment"=>"结算时间（即佣金生效时间，规则与具体产品关联），推广账户：仅已结算状态的保单存在结算时间（包括正负佣金）；保通账户：保单回执后生成结算时间","null"=>true))
        ->addColumn('status', 'enum',array('values' =>'0,1,2,3,4',"comment"=>"状态:0=默认,1=佣金分润中,2=佣金分润成功,3=佣金分润失败,4=退保","null"=>true))
        ->addColumn('type', 'enum', array('values' => "0,1,2",'default'=>"1","comment"=>"关系类型:0=其他,1=云栖,2=语雀","null"=>true))
        ->addColumn('createtime', 'integer', array('limit' => 10,"comment"=>"新增时间","null"=>true))
        ->addColumn('updatetime', 'integer', array('limit' => 10,"comment"=>"更新时间","null"=>true))
        ->addIndex(array('user_id'))
        ->addIndex(array('ware_id'))
        ->addIndex(array('product_id'))
        ->addIndex(array('order_no'))
        ->create();
    }
}
